<?php
	include(ROOTPATH .'include'. DS .'protect.php');
	//include(ROOTPATH .'include'. DS .'checkUserLogin.php');
	include(ROOTPATH .'include'. DS .'initUser.php');

$user_id = (int)getQuery('id');
if($user_id == 0)
	$user_id = $user -> id()  ;
	
$page 				= 		getPage('page');
$tagsUrl 			= 		$_GET['tag'];
$searchTag 			= 		$_GET['searchTag'];
$type 				=		$_GET['type'];
$searchTag 			== 		'' ? '' :  $like = '( `name` like "%'. $searchTag .'%"" )';

$fromType			=		$_GET['fromType']  ? $_GET['fromType'] : $fromType ;

//$fromTypeId = $dbs -> select('SELECT * FROM `'. DB_PRE.'tag_menu` WHERE `name` = "'. $fromType .'" and parentId = 3 ');

//print_r($fromTypeId);
//$fromTypeId = $fromTypeId[0]['id'];

/*1!|2!|3!29|4!|5!44,45,46,47,48,49|6!52,53|7!54,55,56,57*/
$tagMenus = explode('|',$tagsUrl); 
 
$where = '';
$like = '';
$i = 0 ;
foreach($tagMenus as $tMs){
	$tM = explode('!',$tMs);
	if($tM[1]=='') continue;
	$ids = explode(',',$tM[1]);
	
	foreach( $ids as $id){
		$or = $i == 0 ? '' : ' or ';
		$where .= $or .'( `tag` =  '.$tM[0].' and `tagMenu` ='.$id .' )';	
		$i++;
	}	
}
//if( $fromTypeId != 0 )
//	$where == '' ? $where = ' `tagMenu` = '. $fromTypeId  : $where  = $where .' and ( `tag` = 3 and `tagMenu` = '. $fromTypeId .' ) '  ;

$where == '' ? '' : $where  = ' where ' . $where ;


$sqlCount = 'SELECT distinct parentId FROM `'. DB_PRE.'filetag` '. $where .' ORDER BY `id` DESC';//
$sql= $sqlCount .' limit '.(($page-1)* MEDIA_PAGESIZE ).','.  MEDIA_PAGESIZE ;
$tagsCount = $dbs -> select($sqlCount);
$tags = $dbs -> select($sql);

$total = count($tagsCount) ;

?>